import 'package:enjoy_plus/pages/login/index.dart';
import 'package:enjoy_plus/pages/notice/index.dart';
import 'package:enjoy_plus/pages/profile/index.dart';
import 'package:enjoy_plus/pages/tab_bar_page.dart';
import 'package:enjoy_plus/utils/token.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      routes: {
        '/': (context) => TabBarPage(),
        '/detail': (context) => NoticeDetail(),
        '/login': (context) => LoginPage(),
        //'/profile': (context) => ProfilePage(),
      },
      initialRoute: '/',
      onGenerateRoute: (settings) {
        final token = TokenManager().getToken();
        if (token == null) {
          return MaterialPageRoute(builder: (context) => LoginPage());
        }

        if (settings.name == '/profile') {
          return MaterialPageRoute(builder: (context) => ProfilePage());
        }
        return null;
      },
    ),
  );
}
